//
//  NoticeViewController.m
//  ChatApp
//
//  Created by DJL on 15/12/21.
//  Copyright © 2015年 DJL. All rights reserved.
//

#import "NoticeViewController.h"
#import "NoticeTableViewCell.h"
static NSString *KTableViewCell = @"cell";
@interface NoticeViewController ()<UITableViewDataSource,UITableViewDelegate,NoticeCellDelegate>
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *addArray;
@end

@implementation NoticeViewController
+(instancetype)shareNoticeViewController
{
    static NoticeViewController *apply = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        apply = [[NoticeViewController alloc] init];
        
    });
    
    return apply;
}

- (void)getWithUserName:(NSString *)userName message:(NSString *)message {
    
    static int a = 0;
    if (a == 0) {
        self.addArray = [NSMutableArray array];
    }
    a++;
    
    NSDictionary *dicd = [NSDictionary dictionaryWithObjectsAndKeys:userName, @"name", message, @"message", nil];
    [self.addArray addObject:dicd];
    [self.tableView reloadData];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"通知";
    
    [self createTableView];
}
- (void)createTableView {
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[NoticeTableViewCell class] forCellReuseIdentifier:KTableViewCell];
    
    [self.view addSubview:self.tableView];
  
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.addArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NoticeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:KTableViewCell];
    cell.delegate = self;
    cell.userName = [[self.addArray objectAtIndex:indexPath.row] objectForKey:@"name"];
    cell.message = [[self.addArray objectAtIndex:indexPath.row] objectForKey:@"message"];
    cell.num = indexPath.row;
    NSLog(@"88888888%@", cell.userName);
    return cell;

    
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:KTableViewCell];
//    cell.textLabel.text = @"好友邀请";
//    UIButton *add = [UIButton buttonWithType:UIButtonTypeCustom];
//    [add setTitle:@"添加" forState:UIControlStateNormal];
//    add.frame = CGRectMake(self.view.frame.size.width - 100, 5, 40, 30);
//    [add setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    add.backgroundColor = [UIColor colorWithWhite:0.800 alpha:1.000];
//    add.layer.cornerRadius = 5;
//    add.tag = indexPath.row + 100;
//    [add addTarget:self action:@selector(addAct:) forControlEvents:UIControlEventTouchUpInside];
//    UIButton *refused = [UIButton buttonWithType:UIButtonTypeCustom];
//    [refused setTitle:@"拒绝" forState:UIControlStateNormal];
//    refused.frame = CGRectMake(self.view.frame.size.width - 50, 5, 40, 30);
//    [refused setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    refused.backgroundColor = [UIColor colorWithWhite:0.800 alpha:1.000];
//    refused.layer.cornerRadius = 5;
//    refused.tag = indexPath.row + 1000;
//     [refused addTarget:self action:@selector(refusedAct:) forControlEvents:UIControlEventTouchUpInside];
//    [cell addSubview:add];
//    [cell addSubview:refused];
    
    return cell;
    
    
}
////添加方法
//- (void)addAct:(UIButton *)but {
//    
//    
//    NSLog(@"添加");
//}
////拒绝方法
//- (void)refusedAct:(UIButton *)but {
//    
//    NSLog(@"拒绝");
//    
//}
- (void)pass:(BOOL)pass num:(NSInteger)num {
    
    if (pass == YES) {
        [self.addArray removeObjectAtIndex:num];
    }
    [self.tableView reloadData];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 80;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
